﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/FullSite.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<ToppingControl.Models.Top_Waste.TOP_WASTE_DS>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    WASTE
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 <style type="text/css">
      .btn
      {
         font-size: 24px !important;
      }
      .hide
      {
         display: none;
      }
      
      .fontTB
      {
         font-size: 18pt !important;
         padding: 20px 0px;
      }
      input[type="text"], #cpd
      {
         font-size: 1em;
         height: 1.5em;
         line-height: 2em;
      }
      </style>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="MainContent2" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="TableContent" runat="server">
   <div class="float-left" style="width: 50%; margin-right: 0; margin-left: 25px;">
      <table width="100%" class="fontTB shadow">
         <tr class="head" >
          <td colspan="2" class="cell" style="padding: 10px 0px; border-top:1px solid #000000">
                WASTE</td>
         </tr>
         <tr class="rowb">
            <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
               DATE :
            </td>
            <td class="cell" id="dt">
             <%= WinNemoLib.DateUtil.ToDisplayDate(DateTime.Now, WinNemoLib.DateUtil.eLanguage.EN) %>
            </td>
         </tr>
           <tr class="rowb">
            <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
                SHIFT :</td>
            <td class="cell" >
              <%= ToppingControl.Models.SessionBag.Current.shift %> </td>
         </tr>
         <tr class="rowb">
            <td class="head cell text-right" style="padding: 10px 0px; width: 35%; ">
               MATERIAL :
            </td>
            <td class="cell" id="Td1">
            
             <input type="text" id="txtCpd" class="request" maxlength="30" />
            </td>
         </tr>
         <tr class="rowb">
            <td class="head cell text-right" style="padding: 10px 0px; width: 35%; ">
                LOT</td>
            <td class="cell" id="Td1">
            
             <input type="text" id="txtLot" class="request" maxlength="30" /></td>
         </tr>
         <tr class="rowb">
            <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
               REASON :
            </td>
            <td class="cell" id="txtR">
               <input type="text" id="txtRea" class="request" maxlength="2" />
            </td>
         </tr>
         <tr class="rowb">
            <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
               QTY (Kg)</td>
            <td class="cell" id="qty">
               <input type="text" id="txtqty"  class="auto"   /></td>
         </tr>
         <tr class="head"><td  style="padding: 10px 0px;">
         <button id="back" >BACK</button></td><td><button id="save">SAVE</button>
         </td></tr>
      </table>
      
   </div>
   <div style="" class="float-left">
         <table width="90%" class="shadow fontTB" style="margin-left:25px ">
            <tr class="head">
               <td colspan="4" class="cell" 
                    style="padding: 10px 0px; border-top:1px solid #000000">
                  Record Summary
               </td>
            </tr>
            <tr style="background-color: #ccc; font-weight: bolder;">
               <td class="cell" style="padding: 5px 5px; text-align:center">
                  Material
               </td>
               <td class="cell" style="padding: 5px 5px; text-align:center">
                   Lot</td>
               <td class="cell"  style="text-align:center">
                  Reason
               </td>
               <td class="cell" style="text-align:center">
                  Qty
               </td>
            </tr>

              <%
            int i = 0;
            
            foreach (var item in Model)
            {
               i = i + 1;
               string trrow = "rowa";
               if (i % 2 == 0) trrow = "rowb";
            
         %>
         <tr class='<%= trrow %>'    style="padding: 10px 0px; line-height:50px">
         
            <td   style="padding: 10px 5px; line-height:50px">
                <div   style="padding: 10px;  width:200px; "> <%: Html.DisplayFor(modelItem => item._Matcd) %></div>
            </td>

            <td   style="padding: 10px 5px; line-height:50px">
              <div   style="padding: 10px; text-align:center; width:200px; "><%: Html.DisplayFor(modelItem => item._Reason) %></div>
            </td>

            <td>
              <div   style="padding: 10px; text-align:right; width:100px; "><%: Html.DisplayFor(modelItem => item._Reason) %></div>
            </td>
            <td>
                <div   style="padding: 10px; text-align:right; width:150px; "><%: Html.DisplayFor(modelItem => item._Qty) %></div>
            </td>
  
           
         </tr>
         <% } %>
         </table>
      </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ScriptsSection" runat="server">
   <% if (false)
      { %>
   <script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
   <% } %>
   <script src='<%: Url.Content("~/Scripts/comboUI.js") %>' type="text/javascript"></script>
   <script src='<%: Url.Content("~/Scripts/autoNumeric.min.js") %>' type="text/javascript"></script>
   <script src='<%: Url.Content("~/Scripts/autoNumeric.js") %>' type="text/javascript"></script>
   <script src='<%: Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>

   <script type="text/javascript">
       $(function () {
           $('.auto').autoNumeric({ vMin: '-9999.999', vMax: '9999.999', aPad: false });
           $("#txtShift").setMask("3");
           $("#txtlen").setMask("9999.999").addClass("right");
           $("#txtRea").setMask("99").addClass("right");
           $("#txtCpd").focus();
           //         $("#txtdt").dateEntry({ dateFormat: 'dmy/' });
           $("#back,#save").button({
               icons: { primary: "" }
           }).click(function () {
               var btnId = $(this).attr("id");
               if (btnId == 'save') {
                   Save_data();
               }
               else {
                   var url = '<%= Url.Action("Index") %>';
                   window.location = url;
               }
           })

           function Save_data() {
               var blnR = 'true';
               $(".request").each(function () {

                   $(this).parent().find("font").empty();
                   if ($(this).val() == '') {
                       if (blnR == 'true') {
                           blnR = false;
                           $(this).focus();
                           alert('ระบุค่าไม่ครบ');
                       }
                       $(this).parent().append("<font color='red'>*</font>");
                       return;
                   }
               });


               if (blnR == 'true') {
                   var getUsersUrl = '<%=Url.Action("INS_WASTE_DATA") %>';
                   var act = '<%=Url.Action("WASTE") %>';

                   callScriptMethod(getUsersUrl, {
                       thedata: {
                           _Topno: '1',
                           _Empname: '<%: User.Identity.Name %>',
                           _Qty: $("#txtqty").val(),
                           _Reason: $("#txtRea").val(),
                           _Matcd: $("#txtCpd").val().toUpperCase(),
                           _Lot: $("#txtLot").val(),
                           _Wsdate: '<%= WinNemoLib.DateUtil.ToDisplayDate(DateTime.Now, WinNemoLib.DateUtil.eLanguage.EN) %>',
                           _Shift: '<%= ToppingControl.Models.SessionBag.Current.shift %>'
                       }
                   }, act)
               }
           }

           $.post('<%=Url.Action("Get_CPD","CPD_USE") %>', function (data) {
               $('#txtCpd').autocomplete({
                   source: data,
                   change: function (event, ui) { }
               });
           });


           function callScriptMethod(url, jsonObject, action, callback, async) {

               callback = callback || function () { };
               async = (async == null || async);

               $.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: url,
                   data: JSON.stringify(jsonObject),
                   dataType: "json",
                   async: async,
                   success: function (data) {
                       alert(data.message);
                       if (data.success != "0") {
                           $("#txtqty").val("");
                           $("#txtRea").val("");
                           $("#txtCpd").val("");
                           $("#txtdt").val("");
                           window.location = action;
                       }
                   },
                   error: function (xhr, status, error) {
                       var err = xhr.responseText;
                       alert(err.Message);
                   }
               });
           }

       });
    </script>
</asp:Content>